<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>费用查询</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div th:replace="~{/ :: #header}"></div>

<h2>费用查询</h2>
<input type="text" id="phone" placeholder="请输入电话号码">
<button onclick="queryBilling()">查询话费</button>

<h3>话费信息</h3>
<div id="billing-info"></div>

<script>
    function queryBilling() {
        const phone = $('#phone').val();
        $.get(`/billing/info?phoneNumber=${phone}`, function(data) {
            const userInfo = `<p>用户名: ${data.userName}</p>
                                  <p>电话号码: ${data.phoneNumber}</p>
                                  <p>本地话费: ${data.localFee}</p>
                                  <p>长途话费: ${data.longDistanceFee}</p>
                                  <p>话费总计: ${data.totalFee}</p>`;
            $('#billing-info').html(userInfo);
        }).fail(function() {
            $('#billing-info').html('<p>查询失败，请检查电话号码是否正确。</p>');
        });
    }
</script>
</body>
</html>